$i=1;
open(TPED,">imp_1000genome.tped");
for($i=1;$i<23;$i++)
{
	$phased = "/data1/bsi/refdata/genetics/1000Genomes/processed_data/release/20100804/beagle/ALL/ALL.chr$i.20100804.b37p0.bgl.phased.gz";	
	$marker = "/data1/bsi/refdata/genetics/1000Genomes/processed_data/release/20100804/beagle/ALL/ALL.chr$i.20100804.b37p0.markers.gz";
	open BUFF,"gunzip -c $phased |" or die "no file found: $phased\n";
	$line = <BUFF>;
	@array = split(/ /,$line);
	shift(@array);
	shift(@array);
	#print @array."\n";
	open(TFAM,">imp_1000genome.tfam");
	for($y=0;$y<@array;$y++)
	{
		chomp($array[$y]);
		print TFAM "$array[$y] $array[$y] 0 0 -9 -9\n";
		$y++;
	}
	close(TFAM);
	open BUFF1,"gunzip -c $marker |" or die "no file found: $marker\n";	
	while($line=<BUFF1>)
	{
		chomp($line);
		@arr = split(" ",$line);
		$hash{$arr[0]} = $line;
	}
	close(BUFF1);
	while($line =<BUFF>)
	{
		chomp($line);
		@arr = split(" ",$line);
		shift(@arr);
		$rsid = shift(@arr);
		$line = join(" ",@arr);
		if(exists($hash{$rsid}))
		{
			@mark = split(" ",$hash{$rsid});
			print TPED "$i $rsid 0 $mark[1] $line\n";
		}
		else
		{
			die "$arr[0]\tchr$i\n";
		}
	}
	 close(BUFF);
}
close(TPED);
